using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPMasterImportService
    {
        ISession session;

        public MRPMasterImportService(ISession session)
        {
            this.session = session;
        }
        public MRPMasterImportService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpmasterimport(MRPMasterImport mrpmasterimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpmasterimportX);
            tx.Commit();
        }

        public void UpdateMrpmasterimport(MRPMasterImport mrpmasterimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpmasterimportX);
            tx.Commit();
        }

        public void DeleteMrpmasterimport(MRPMasterImport mrpmasterimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpmasterimportX);
            tx.Commit();
        }

        public IList<MRPMasterImport> GetAllMrpmasterimport(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPMasterImport");
            IList<MRPMasterImport> list = query.List<MRPMasterImport>();
            if (evict)
            {
                foreach (MRPMasterImport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPMasterImport GetAllMrpmasterimportByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPMasterImport as c where c.Masterimportcode= :x");
            query.SetString("x", id);
            MRPMasterImport s = (MRPMasterImport)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPMasterImport> GetMrpmasterimportByQuery(IQuery query, Boolean evict)
        {
            IList<MRPMasterImport> list = query.List<MRPMasterImport>();
            if (evict)
            {
                foreach (MRPMasterImport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
